package iq.number;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * DecimalFormat��BigDecimalС����������������
 *
 */
public class NumberTest {
	public static void main(String[] args) {
		new NumberTest().test1();
	}
	public void test1() {
		System.out.println("test BigDecimal & DecimalFormat");
		Double oriValue = 245.205;
		BigDecimal bd = new BigDecimal(oriValue).setScale(2,
				BigDecimal.ROUND_HALF_UP);
		System.out.println();
		DecimalFormat df2 = new DecimalFormat("0.00");
		String text = String.format(
				"original : %s, BigDecimal : %s, DecimalFormat : %s", oriValue,
				bd, df2.format(oriValue));
		System.out.println(text);

		oriValue = 72.675;
		System.out.println(new BigDecimal(oriValue));
		//������String����Ͳ���������
		bd = new BigDecimal(oriValue).setScale(2, BigDecimal.ROUND_HALF_UP);
		System.out.println();
		text = String.format(
				"original : %s, BigDecimal : %s, DecimalFormat : %s", oriValue,
				bd, df2.format(oriValue));
		System.out.println(text);

		oriValue = 172.675;
		bd = new BigDecimal(oriValue).setScale(2, BigDecimal.ROUND_HALF_UP);
		System.out.println();
		text = String.format(
				"original : %s, BigDecimal : %s, DecimalFormat : %s", oriValue,
				bd, df2.format(oriValue));
		System.out.println(text);

	}
}